package utils

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func GkRealnameAuth(oid string, num string, name string, key string) bool {
	url := "https://cid.ssl.gkshuju.com/api/v3/default/cid"
	// oid := "cui1000001"
	// num := "412723199210113436"
	// name := "崔凯迪"
	// key := "54dd62feb72f11ed93e79e1ef89aee63"

	// 构建请求参数
	data := fmt.Sprintf("oid=%s&num=%s&name=%s&key=%s", oid, num, name, key)
	fmt.Println(data)
	body := bytes.NewBuffer([]byte(data))

	// 发起 POST 请求
	response, err := http.Post(url, "application/x-www-form-urlencoded", body)
	if err != nil {
		fmt.Println("Error sending POST request:", err)
		return false
	}
	defer response.Body.Close()

	// 解析响应
	bodyBytes, err := io.ReadAll(response.Body)
	if err != nil {
		fmt.Println("Error reading response body:", err)
		return false
	}
	bodyString := string(bodyBytes)

	// 处理响应结果
	if response.StatusCode == http.StatusOK {
		fmt.Println("Response body:", bodyString)
		// 根据需要解析响应内容
	} else {
		fmt.Println("Response status code:", response.StatusCode)
	}

	return false
}
